//
//  SSSRecommendRecordCell.m
//  SSSMerchant
//
//  Created by Darker on 2017/3/23.
//  Copyright © 2017年 xnxin. All rights reserved.
//

#import "SSSRecommendRecordCell.h"
#import "ZDKitManager.h"
#import "SSSRecommendModel.h"

@interface SSSRecommendRecordCell()
{
    
    UIView *centerView;
}

/** headerImageView */
@property (nonatomic, strong) UIImageView *userHeaderImageView;

/** userName */
@property (nonatomic, strong) UILabel *userNameLabel;

/** time */
@property (nonatomic, strong) UILabel *timeLabel;

/** time1 */
@property (nonatomic, strong) UILabel *timeLabel1;


@end

@implementation SSSRecommendRecordCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setSubViews];
    }
   
    return self;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setSubViews{
    
    
    
    //头像
    _userHeaderImageView = [UIImageView new];
    [self.contentView addSubview:_userHeaderImageView];
    _userHeaderImageView.backgroundColor = [UIColor redColor];
    _userHeaderImageView.sd_layout
    .centerYEqualToView(self.contentView)
    .leftSpaceToView(self.contentView,WidthIos6CompeteWithCurrent(15))
    .widthIs(HeigthIos6CompeteWithCurrent(51))
    .heightIs(HeigthIos6CompeteWithCurrent(51));
    _userHeaderImageView.layer.cornerRadius = _userHeaderImageView.frame.size.height/2;
    _userHeaderImageView.layer.masksToBounds = YES;
    
    centerView = [[UIView alloc]init];
    [self.contentView addSubview:centerView];
    centerView.sd_layout
    .centerYEqualToView(self.contentView)
    .leftSpaceToView(_userHeaderImageView,WidthIos6CompeteWithCurrent(14))
    .widthIs(self.contentView.frame.size.width - WidthIos6CompeteWithCurrent(100))
    .heightIs(HeigthIos6CompeteWithCurrent(40));
    
    //姓名
    _userNameLabel = [[UILabel alloc]init];
    _userNameLabel.text =@"";
    _userNameLabel.textAlignment =NSTextAlignmentLeft;
    _userNameLabel.font = [SSSFont systemFontOfSize:15];
    _userNameLabel.textColor = [UIColor colorWithHex:@"6D6D6D"];
    [centerView addSubview:_userNameLabel];
    _userNameLabel.sd_layout
    .leftSpaceToView(centerView,0)
    .topSpaceToView(centerView,0)
    .rightSpaceToView(centerView,0)
    .heightIs(centerView.frame.size
              .height/2);
    
    //时间
    _timeLabel = [[UILabel alloc]init];
    _timeLabel.text =@"2017-2-14";
    _timeLabel.textAlignment =NSTextAlignmentLeft;
    _timeLabel.font = [SSSFont systemFontOfSize:15];
    _timeLabel.textColor = [UIColor colorWithHex:@"6D6D6D"];
    [centerView addSubview:_timeLabel];
    _timeLabel.sd_layout
    .leftSpaceToView(centerView,0)
    .topSpaceToView(_userNameLabel,0)
    .widthIs([ZDKitManager zd_AutoSizeOfWidthWithText:_timeLabel.text font:_timeLabel.font height:centerView.frame.size.height/2])
    .heightIs(centerView.frame.size.height/2);
    
    _timeLabel1 = [[UILabel alloc]init];
    _timeLabel1.text =@"";
    _timeLabel1.textAlignment =NSTextAlignmentLeft;
    _timeLabel1.font = [SSSFont systemFontOfSize:15];
    _timeLabel1.textColor = [UIColor colorWithHex:@"6D6D6D"];
    [centerView addSubview:_timeLabel1];
    _timeLabel1.sd_layout
    .leftSpaceToView(_timeLabel,WidthIos6CompeteWithCurrent(10))
    .topEqualToView(_timeLabel)
    .bottomEqualToView(_timeLabel)
    .rightSpaceToView(centerView,0);

    //线
    UIView *lineView = [UIView new];
    lineView.backgroundColor = [UIColor colorWithHex:@"E6E6E6"];
    [self.contentView addSubview:lineView];
    lineView.sd_layout
    .leftEqualToView(_userHeaderImageView)
    .bottomSpaceToView(self.contentView,0)
    .rightSpaceToView(self.contentView,WidthIos6CompeteWithCurrent(15))
    .heightIs(0.5);
    
    
}
- (void)setModel:(SSSRecommendModel *)model{
    
    _model = model;
    self.userNameLabel.text = model.name;
    NSURL *avatar = [NetUrlTool urlStrWithPath:model.avatar];
    [_userHeaderImageView sd_setImageWithURL:[NSURL URLWithString:avatar] placeholderImage:[UIImage imageNamed:@"icon_headportrait"]];
    
    if (model.recomTime.length<=0) {
        self.timeLabel.text = @"";
        self.timeLabel1.text = @"";
    }else{
        
        NSString *subStr = [model.recomTime substringWithRange:NSMakeRange(0,model.recomTime.length - 3)];
        self.timeLabel.text = [NSString timeDateStrFromTimeStamp:subStr];
        _timeLabel.sd_layout
        .leftSpaceToView(centerView,0)
        .topSpaceToView(_userNameLabel,0)
        .widthIs([ZDKitManager zd_AutoSizeOfWidthWithText:_timeLabel.text font:_timeLabel.font height:centerView.frame.size.height/2])
        .heightIs(centerView.frame.size.height/2);
        self.timeLabel1.text = [NSString timeDateStrFromTimeHHmmssStamp:model.recomTime];
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
